export function combine(n: number, k: number): number[][] {
    const ret: number[][] = [];
    const path: number[] = [];
    backTrace(1, n, k, path, ret);
    return ret;
};

function backTrace (startNum: number, n: number, k: number, path: number[], ret: number[][]) {

    if (path.length === k) {
        ret.push([...path]);
        return;
    }

    let i = startNum;
    // 可供选择的数字有多少个
    let hasCount = n - i + 1;
    // 还需要多少个数字
    let needCount = k - path.length;
    while (i <= n && hasCount >= needCount) {
        path.push(i);
        backTrace(i+1, n, k, path, ret);
        path.pop();
        i++;
        hasCount = n - i + 1;
    }
}